//
//  ViewController.m
//  FlowTest
//
//  Created by yan on 2020/11/24.
//

#import "ViewController.h"
#import "ZJSegmentStyle.h"
#import "ZJScrollPageView.h"
#import "IndexViewController.h"
#define XH_FULLSCREEN \
({\
BOOL isPhoneX = NO;\
if (@available(iOS 11.0, *)) {\
    isPhoneX = ([[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0) ? YES : NO;\
}(isPhoneX);})
@interface ViewController ()<ZJScrollPageViewDelegate>

@property(strong,nonatomic)UITableView *tableView;

@property(strong,nonatomic)ZJScrollPageView *scrollPageView;

@property(strong,nonatomic)NSArray *titleList;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
  //  self.view.backgroundColor = [UIColor redColor];
    self.titleList = @[@"全部",@"待联系",@"待上门",@"服务中",@"待确定",@"已完成"];
    [self setTitleNavgtion];
    [self initZJScroller];
}


/**设置导航栏内容*/
-(void)setTitleNavgtion{
    UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 300, 30)];
    searchBar.placeholder = @"搜索工单";
    self.navigationItem.titleView = searchBar;
    
    UIBarButtonItem *rightBaritem = [[UIBarButtonItem alloc] initWithTitle:@"通知" style:UIBarButtonItemStylePlain target:self action:@selector(onClickedBtn)];
    self.navigationItem.rightBarButtonItem = rightBaritem;
}

/**跳转设置通知界面*/
- (void)onClickedBtn {
    
}

- (void)initZJScroller{
    //必要的设置, 如果没有设置可能导致内容显示不正常
    self.automaticallyAdjustsScrollViewInsets = NO;
    ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
   // style.scrollLineHeight = 5;
 //   style.gradualChangeTitleColor = YES;
    // 显示附加的按钮
    style.scrollTitle = YES;
    style.showCover = NO;
    style.showLine = YES;
    style.contentViewBounces = NO;
    style.scrollTitle = NO;
    style.scrollLineColor = [UIColor blackColor];
    style.selectedTitleColor = [UIColor colorWithRed:51.0/255.0  green: 51.0/255.0 blue:51.0/255.0  alpha: 1.0];
    style.normalTitleColor = [UIColor colorWithRed:138.0/255.0  green: 138.0/255.0 blue:138.0/255.0  alpha: 1.0];
    float Y = 74;
    if (XH_FULLSCREEN) {
        Y += 24;
    }
    CGRect scrollPageViewFrame = CGRectMake(0,Y, self.view.bounds.size.width, self.view.bounds.size.height-Y);
    ZJScrollPageView *scrollPageView = [[ZJScrollPageView alloc] initWithFrame:scrollPageViewFrame segmentStyle:style titles:_titleList parentViewController:self delegate:self];
    scrollPageView.backgroundColor = [UIColor redColor];
      self.scrollPageView = scrollPageView;
    __weak __typeof(self) weakSelf = self;
    [self.view addSubview:self.scrollPageView];
}


#pragma mark ZJScrollPageViewDelegate

/** 将要显示的子页面的总数 */
- (NSInteger)numberOfChildViewControllers{
    return _titleList.count;
}

 
- (UIViewController<ZJScrollPageViewChildVcDelegate> *)childViewController:(IndexViewController<ZJScrollPageViewChildVcDelegate> *)reuseViewController forIndex:(NSInteger)index{
    if (reuseViewController == nil) {
        reuseViewController = [[IndexViewController alloc] init];
    }
    OrderListType type = OrderListTypeAll;
    switch (index) {
        case 0:
            type = OrderListTypeAll;
            break;
        case 1:
            type = OrderListTypeContact;
            break;
        case 2:
            type = OrderListTypeHome;
            break;
        case 3:
            type = OrderListTypeServeing;
            break;
        case 4:
            type = OrderListTypeConfirmed;
            break;
        case 5:
            type = OrderListTypeComplete;
            break;
        default:
            break;
    }
    reuseViewController.type = type;
    return reuseViewController;
}



@end
